package com.share.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.share.mapper.SysMenuMapper;
import com.share.service.ISysMenuService;
import com.share.user.admin.dtos.PayloadDTO;
import com.share.user.admin.pojos.SysMenu;
import com.share.user.admin.vo.MenuItem;
import com.share.util.thread.ThreadLocalUtils;
import com.share.utils.MenuTreeBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * <p>
 * 菜单表 服务实现类
 * </p>
 *
 * @author 胡先生
 * @since 2024-11-30
 */
@Service
@Transactional
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService {


    @Override
    public List<MenuItem> getRouter() {
        PayloadDTO payloadDTO = ThreadLocalUtils.get();
        List<SysMenu> sysMenus = this.baseMapper.selectMenuListByUserId(payloadDTO.getId());
        return MenuTreeBuilder.buildMenuTree(sysMenus);
    }


}
